package org.example.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
import org.example.service.TestDataService;
import org.example.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yangzhenyu
 * @version 1.0
 * @description:
 * @date 2023/4/26 10:42
 */
@RestController
@RequestMapping(value="api/demo")
public class TestController {

    @Autowired
    private TestService service;
    @Autowired
    private TestDataService testDataService;
    @GetMapping("/execute")
    public String executeOneOffJob() {
        OneOffJobBootstrap myOneOffJob = SpringUtil.getBean("myOneOffJob");
        myOneOffJob.execute();
        return "success";
    }


    /**
     * add many data
     * @author yangzhenyu
     */
    @GetMapping("/addAll/{num}")
    public Boolean single(@PathVariable(value = "num") Integer num) {
        if (ObjectUtil.isNotNull(num)){
            return service.addAll(num);
        }
        return Boolean.FALSE;
    }

}
